#include<stdio.h>
#include<stdlib.h>
#define Len 7
//法一：额外数组
//int* rotate(int* nums, int numsSize, int k) {
//    int arr[Len] = { 0 };
//    for (int i = 0; i < numsSize; i++)
//    {
//        arr[i] = nums[i];
//    }
//    for (int i = 0; i < numsSize; i++)
//    {
//        nums[(i + k) % numsSize] = arr[i];
//    }
//    return nums;
//}

//法三：数组翻转法
void swap(int* a, int* b) {
    int t = *a;
    *a = *b, * b = t;
}

void reverse(int* nums, int start, int end) {
    while (start < end) {
        swap(&nums[start], &nums[end]);
        start += 1;
        end -= 1;
    }
}

void rotate(int* nums, int numsSize, int k) {
    k %= numsSize;
    reverse(nums, 0, numsSize - 1);
    reverse(nums, 0, k - 1);
    reverse(nums, k, numsSize - 1);
}
int main()
{
	int nums[7] = { 1,2,3,4,5,6,7 };
	int numsSize = sizeof(nums) / sizeof(nums[0]);
	int k = 3;
    rotate(nums, numsSize, k);
    for (int i = 0; i < numsSize; i++)
    {
        printf("%d ", nums[i]);
    }
	return 0;
}


